package com.it.service.impl;

import com.it.Bean.Admin;
import com.it.dao.AdminDao;
import com.it.dao.impl.AdminDaoimpl;
import com.it.db.DBManager;
import com.it.service.AdminService;

import java.sql.Connection;
import java.sql.SQLException;

public class AdminServiceimpl implements AdminService {
    @Override
    public Admin isVialdData(String username, String password) {
        AdminDao dao = new AdminDaoimpl();
        Admin admin = new Admin();
        admin.setUsename(username);
        admin.setPassword(password);
        try {
            Admin login = dao.Login(admin);
            if (login!=null)
                return login;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }


    @Override
    public boolean add(Admin admin) {

        //创建dao层的对象
        AdminDao adminDao = new AdminDaoimpl();
        //调用AdminDaoImpl对象中的 public void setConnection(Connection connection)方法连接数据库
        boolean isRight = false;
    /*    try {
            //调用dao层的添加方法，因为抛出了SQLException异常，所以要处理它。
            isRight = adminDao.save(admin);
            //手动提交事物，添加到数据库中的数据才会真实在存在
            //conn.commit();
        } catch (SQLException e) {
           *//* try {
                //回滚事物，取消之前的操作
               // conn.rollback();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }*//*
            e.printStackTrace();
        }*/
        return isRight;
    }

    public static void main(String[] args) {
        AdminService service = new AdminServiceimpl();
        Admin admin = new Admin();
        admin.setUsename("blues");
        admin.setPassword("111111");
        admin.setAge(50);
        admin.setShcool("foreknow");
        //调用业务层的添加方法
        boolean isRight = service.add(admin);
        if(isRight) {
            System.out.println("添加成功......");
        }else {
            System.out.println("添加失败......");
        }

//    Admin admin = service.isValidate("tom","123456");
//    if(admin!=null){
//      System.out.println(admin.getUsername());
//    }else {
//      System.out.println("此数据没有查询到！！！！！！");
//    }
    }


}
